<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="举报类型：0->视频；1->头像；2->用户评论；3->其他" prop="reportType">
      <el-input v-model="dataForm.reportType" placeholder="举报类型：0->视频；1->头像；2->用户评论；3->其他"></el-input>
    </el-form-item>
    <el-form-item label="举报人id" prop="uid">
      <el-input v-model="dataForm.uid" placeholder="举报人id"></el-input>
    </el-form-item>
    <el-form-item label="举报人" prop="reportMemberName">
      <el-input v-model="dataForm.reportMemberName" placeholder="举报人"></el-input>
    </el-form-item>
    <el-form-item label="" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="举报内容" prop="reportObject">
      <el-input v-model="dataForm.reportObject" placeholder="举报内容"></el-input>
    </el-form-item>
    <el-form-item label="举报状态：0->处理中；1->已处理" prop="reportStatus">
      <el-input v-model="dataForm.reportStatus" placeholder="举报状态：0->处理中；1->已处理"></el-input>
    </el-form-item>
    <el-form-item label="处理结果：0->无效；1->有效；2->恶意" prop="handleStatus">
      <el-input v-model="dataForm.handleStatus" placeholder="处理结果：0->无效；1->有效；2->恶意"></el-input>
    </el-form-item>
    <el-form-item label="反馈内容" prop="note">
      <el-input v-model="dataForm.note" placeholder="反馈内容"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          reportType: '',
          uid: '',
          reportMemberName: '',
          createTime: '',
          reportObject: '',
          reportStatus: '',
          handleStatus: '',
          note: ''
        },
        dataRule: {
          reportType: [
            { required: true, message: '举报类型：0->视频；1->头像；2->用户评论；3->其他不能为空', trigger: 'blur' }
          ],
          uid: [
            { required: true, message: '举报人id不能为空', trigger: 'blur' }
          ],
          reportMemberName: [
            { required: true, message: '举报人不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          reportObject: [
            { required: true, message: '举报内容不能为空', trigger: 'blur' }
          ],
          reportStatus: [
            { required: true, message: '举报状态：0->处理中；1->已处理不能为空', trigger: 'blur' }
          ],
          handleStatus: [
            { required: true, message: '处理结果：0->无效；1->有效；2->恶意不能为空', trigger: 'blur' }
          ],
          note: [
            { required: true, message: '反馈内容不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/common/userreport/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.reportType = data.userReport.reportType
                this.dataForm.uid = data.userReport.uid
                this.dataForm.reportMemberName = data.userReport.reportMemberName
                this.dataForm.createTime = data.userReport.createTime
                this.dataForm.reportObject = data.userReport.reportObject
                this.dataForm.reportStatus = data.userReport.reportStatus
                this.dataForm.handleStatus = data.userReport.handleStatus
                this.dataForm.note = data.userReport.note
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/common/userreport/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'reportType': this.dataForm.reportType,
                'uid': this.dataForm.uid,
                'reportMemberName': this.dataForm.reportMemberName,
                'createTime': this.dataForm.createTime,
                'reportObject': this.dataForm.reportObject,
                'reportStatus': this.dataForm.reportStatus,
                'handleStatus': this.dataForm.handleStatus,
                'note': this.dataForm.note
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
